<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    我是首页
</div>
</body>
</html>

<script src="../js/vue.min.js"></script>
<script src="../js/axios.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {}
        },
        created() {
            // 1.判断是否有token
            let token = localStorage.getItem('token')
            if (!token) {
                // 1.1 如果没有token,则跳转到登录页
                location.href = 'login.html'
                return
            }
            // 1.2 如果有token,则继续请求
            axios({
                method: 'get',
                url: `https://localhost:8080/auth/is_login`,
                // 将请求放到请求头中进行传递
                headers: {
                    token: token
                }
            }).then(resp => {
                if (!resp.data.success) {
                    location.href = 'login.html'
                    return
                }
            })
        }
    })
</script>